
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * 登录管理
 * @author lxn
 */
class Login extends Base_Controller
{
	private static $data = array();
	protected $models=['user_model'];
	public function __construct()
	{	    
		parent::__construct();		
	}

	/**
	 * 登录
	 * @author yxl
	 * 2015-5-20 18:37:11
	 * */
	public function index()
	{  		
		$this->load->view('seller/login.html',self::$data);
	}
	
	
	/**
	 * 登录表单提交
	 * @author yxl
	 * 2015-5-20 19:35:50
	 */
	public function Login()
	{
	    
		$phone = trim($this->input->post('phone'));
		$password = trim($this->input->post('password'));
		$where=['phone'=>$phone,'password'=>md5($password)];
		$sellerData = $this->user_model->login($where);

		if (empty($sellerData))//用户名密码错误
		{
		    show400('用户名或密码错误');
		}else{
		    $this->session->set_userdata('sellerId',$sellerData['userId']);
		    show200([],'登录成功');
		}
	}

	

	/**
	 * 退出系统
	 * */
	public function logout()
	{
	    $this->session->sess_destroy();
	    redirect('seller/login');
	}


	public function reg(){
	    $data=$this->input->post();
	    if($data['password']!=$data['password_reapeat']){
	        show300('两次密码输入不正确');
	    }
	    $phone=$data['phone'];
	    $password=$data['password'];
	    $user=$this->user_model->getWhereRow(['phone'=>$phone]);
	    if($user){
	        show300('该手机号已存在');
	    }
	    $res=$this->user_model->insert_time(['phone'=>$phone,'password'=>md5($password),'userFlag'=>1]);
	    if($res){
	        show200('注册成功');
	    }else{
	        show400('注册失败');
	    }
	}
	
}
/* End of file Login.php */